import 'package:shop/common/shop_material.dart';
import 'package:shop/service/MemberService.dart';
import 'package:shop/utils/MyToast.dart';
import 'package:shop/view/login/LoginIndex.dart';

//设置页面
class Setting extends StatefulWidget {
  Setting({Key key}) : super(key: key);
  @override
  _SettingState createState() => _SettingState();
}

class _SettingState extends State<Setting> {
  MemberService memberService = MemberService();
  @override
  void initState() {
    super.initState();
  }

  _loginOut() async {
    bool res = await memberService.loginOut();
    if (res) {
      MyToast("退出登录");
      route.pop();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("设置"),
        centerTitle: true,
        elevation: 0,
        leading: InkWell(
          onTap: () => route.pop(),
          child: Icon(Icons.arrow_back_ios),
        ),
      ),
      body: Container(
        margin: EdgeInsets.all(20.h),
        child: ListView(
          children: <Widget>[
            _userWidget(),
            _getCard([
              _getItem("管理收货地址"),
              Divider(height: 1),
              _getItem("修改密码"),
              Divider(height: 1),
              _getItem("账号绑定"),
              Divider(height: 1),
              _getItem("实名认证"),
            ]),
            _getCard([
              _getItem("消息推送设置"),
              Divider(height: 1),
              _getItem("隐私政策"),
            ]),
            _getCard([
              _getItem("清理缓存", subWidget: Text("332M")),
              Divider(height: 1),
              _getItem("检查更新", subWidget: Text("最新")),
            ]),
            _getCard([
              _getItem("注销账户"),
            ]),
            InkWell(
              onTap: _loginOut,
              child: Container(
                margin: EdgeInsets.symmetric(horizontal: 40.w, vertical: 30.h),
                height: 80.h,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: Colors.red, borderRadius: BorderRadius.circular(10)),
                child: Text("退出登录",
                    style: TextStyle(color: Colors.white, fontSize: 32.s)),
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(height: 1, width: 100.w, color: Color(0xFFCCCCCC)),
                Text(
                  "   Version5.0.0   ",
                  style: TextStyle(fontSize: 24.s, color: Color(0xFF999999)),
                ),
                Container(height: 1, width: 100.w, color: Color(0xFFCCCCCC)),
              ],
            )
          ],
        ),
      ),
    );
  }

  _getItem(String title, {Widget subWidget, Function() onTap}) {
    return InkWell(
      onTap: onTap,
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 36.h),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Text(
              '$title',
              style: TextStyle(fontSize: 28.s, color: Color(0xFF333333)),
            ),
            subWidget ?? Image.asset("images/user/ic_next.png", height: 26.h)
          ],
        ),
      ),
    );
  }

  Widget _getCard(List<Widget> child) {
    return Container(
      margin: EdgeInsets.only(top: 20.h),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(20.h),
        color: Colors.white,
      ),
      child: Column(
        children: child,
      ),
    );
  }

  Widget _userWidget() {
    return Container(
      height: 188.h,
      width: 710.w,
      padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 30.h),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(20.h), color: Colors.white),
      child: Row(
        children: <Widget>[
          LoginIndex.getHeader(),
          SizedBox(width: 20.w),
          Expanded(
              child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Text(
                "用户昵称",
                style: TextStyle(fontSize: 36.s, fontWeight: FontWeight.bold),
              ),
              Row(
                children: <Widget>[
                  Text("1211212121212",
                      style:
                          TextStyle(color: Color(0xFF666666), fontSize: 24.s)),
                  SizedBox(width: 40.w),
                  Text("赶马ID: 4234234",
                      style:
                          TextStyle(color: Color(0xFF666666), fontSize: 24.s))
                ],
              )
            ],
          )),
          Image.asset("images/user/ic_next.png", height: 26.h)
        ],
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
